const http = require("http");
const webSocket = require("ws");
const server = http.createServer();
const wss = new webSocket.Server({ server });

wss.on("connection", (ws) => {
  console.log("服务端socket建立链接");
  ws.on("message", (message) => {
    console.log(`服务端收到消息内容: ${message}`);
    ws.send(`模拟服务端发送客户端: ${message} --- 服务端消息`);
  });
  ws.on("close", () => {
    console.log("webSocket服务断开链接");
  });
});
server.listen(8080, () => {
  console.log("端口开启");
});
